package generator;
import java.io.*;
import java.util.*;

public class TestGen {

	public static void generate(int n, String file) throws Exception
	{
		if (file.length() == 0)
		{
			System.out.println("no file specified...");
			return;
		}
		
		File f = new File(file);
		if (f.exists())
		{
			System.out.println("Error, file already exists");
			return;
		}
		
		f.createNewFile();
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
		bw.write("init(10)");
		int count = 0;
		byte[][] matrix = new byte[n][n];
		
		for (int i=0; i<n; i++)
		{
			for (int j=i+1; j<n; j++)
			{
				bw.newLine();
				bw.write("insert("+i+","+j+")");
				bw.newLine();
				bw.write("transitive closure?");
				count++;
			}
		}
		
		Random r = new Random();
		while (count != 0)
		{
			int i = r.nextInt(n);
			int j = r.nextInt(n);
			if (matrix[i][j] == 0)
			{
				matrix[i][j] = 1;
				bw.newLine();
				bw.write("delete("+i+","+j+")");
				bw.newLine();
				bw.write("transitive closure?");
				bw.newLine();
				bw.write("insert("+j+","+i+")");
				bw.newLine();
				bw.write("transitive closure?");
				count--;
			}
		}
		
		bw.flush();
	}
}
